package com.lz.football.module.playerCenter.ComboBox
{
	import com.common.utils.Reflection;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import lz.controls.nickScroll.ScrollBarByMc;
	import lz.controls.nickScroll.ScrollBarView;

	/**
	 * 下拉列表菜单 
	 * @author Administrator
	 * 
	 */	
	public class ComboBoxMunu extends Sprite
	{
		private var str:String = "标志着钓鱼岛“国有化”方针正式成立。随后，中国官方媒体宣布，中国2艘海监船当天开始进入钓鱼岛海域巡航，这是中方针对日本政府“购岛”行为的对抗措施。《读卖新闻》认为，中国官方媒体对海监船巡航活动报道得如此之早实属罕见，2艘中方船只很可能反复在钓鱼岛海域行驶，以此宣示主权。";
		/**
		 * 皮肤 
		 */
		private var symbolSkin:MovieClip;
		/**
		 *滚动条 
		 */
//		private var _scrollBar:ScrollBarByMc;
		private var _target:Sprite;
		private var _callBack:Function;
		public function ComboBoxMunu()
		{
			super();
			init();
		}
		/**
		 * 
		 * 
		 */
		private function init():void
		{
			symbolSkin = Reflection.createInstance("com.lz.modul.playerCenter.comboxBg");
			this.addChild(symbolSkin);
//			bar();
//			setData();
		}
//		private function bar():void
//		{
//			_scrollBar = new ScrollBarByMc();
//			_scrollBar.setSize(symbolSkin.width - 20,symbolSkin.height - 10,"little_SkinScrollBar");
//			this.addChild(_scrollBar);
//			_scrollBar.x = 2;
//			_scrollBar.y = 5;
//			_target = new Sprite();
//			_scrollBar.target = _target;
//			_scrollBar.lineScrollSize = 10;//设置滚动量
//			_scrollBar.setPlace();
//			_scrollBar.upData();
			
//		}
		/**
		 * 显示数据 
		 * 
		 */
		public function setData($arr:Array,$value:int):void
		{
			var item:ComboBoxItem;
			var len:int = $arr.length;
			for(var i:int = 0;i < len;i++)
			{
				item = new ComboBoxItem();
				item.y = 19 * i;
				item.x = 2;
				item.data = $arr[i];
				if(item.data.value == $value)
				{
					if(_callBack != null)
						_callBack(item.data);
				}
						
				this.addChild(item);
			}
//			_scrollBar.targetHeight = _target.height;
//			_scrollBar.upData();
			if(len == 0)return;
//			if(_callBack != null)
//			{
//				item = this.getChildAt(0) as ComboBoxItem;
//				_callBack(item.data);
//			}
		}
		private function textString():String
		{
			var s:String = "";
			var va:int;
			for(var i:int = 0;i < 5;i++)
			{
				va = Math.random() * str.length
				s+= str.slice(va,va+1);
			}
			return s;
		}
		/**
		 * 
		 * 
		 */
		public function addEvent():void
		{
			if(this.stage)
				this.stage.addEventListener(MouseEvent.MOUSE_DOWN,onDownHandler);
		}
		/**
		 * 
		 * @param event
		 * 
		 */
		private function onDownHandler(event:MouseEvent):void
		{
			if(event.target.parent == this.parent )
			{
				return;
			}
			if(event.target.parent.parent is ComboBoxItem)
			{
				var item:ComboBoxItem = event.target.parent.parent as ComboBoxItem;
				if(_callBack != null)
					_callBack(item.data);
			}
			if(this.parent)
			{
				this.stage.removeEventListener(MouseEvent.MOUSE_DOWN,onDownHandler);
				this.parent.removeChild(this);
				
			}
		}

		/**
		 *点击回调 
		 */
		public function set callBack(value:Function):void
		{
			_callBack = value;
		}

		/**
		 *销毁 
		 * 
		 */
		public function destroyView():void
		{
			if(this.stage)
				this.stage.removeEventListener(MouseEvent.MOUSE_DOWN,onDownHandler);
			var item:ComboBoxItem;
			while(this.numChildren)
			{
				item = this.removeChildAt(0) as ComboBoxItem;
				if(item == null)continue;
				item.destroyView();
				item = null;
			}
//			_scrollBar = null;
			_target = null;
			symbolSkin = null;
		}
	}
}